package com.hllxd.hism.star.basic.service.service;

import com.hllxd.hism.star.basic.service.dao.mapper.mis.TblDataRockBnProductInfoMapper;
import com.hllxd.hism.star.basic.service.model.TblDataRockBnProductInfo;
import com.hllxd.hism.star.basic.service.model.TblDataRockBnProductInfoExample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Slf4j
@Service("productInfoConfigService")
public class ProductInfoConfigServiceImpl implements ProductInfoConfigService {

    @Autowired
    private TblDataRockBnProductInfoMapper tblDataRockBnProductInfoMapper;

    @Override
    public List<TblDataRockBnProductInfo> listProductInfo() {
        TblDataRockBnProductInfoExample productInfoExample = new TblDataRockBnProductInfoExample();
        TblDataRockBnProductInfoExample.Criteria criteria = productInfoExample.createCriteria();
        List<String> states = Arrays.asList("0", "1");
        criteria.andStateIn(states);
        return tblDataRockBnProductInfoMapper.selectByExample(productInfoExample);
    }

    @Override
    public Long setProductInfo(TblDataRockBnProductInfo aa) {
        long id;
        if (aa.getId() != null && aa.getId() > 0) {
            aa.setState("1");
            id = tblDataRockBnProductInfoMapper.updateByPrimaryKeySelective(aa);
        } else {
            aa.setState("0");
            id = tblDataRockBnProductInfoMapper.insertSelective(aa);
        }
        return id;
    }

    @Override
    public Long delProductInfo(Long id, String userName) {
        TblDataRockBnProductInfo aa = new TblDataRockBnProductInfo();
        aa.setId(id);
        aa.setState("2");
        aa.setLastAlterPerson(userName);
        return (long) tblDataRockBnProductInfoMapper.updateByPrimaryKeySelective(aa);
    }

    @Override
    public TblDataRockBnProductInfo getProductInfo(Long id) {
        return tblDataRockBnProductInfoMapper.selectByPrimaryKey(id);
    }
}
